/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.Ufes.exeSwing.Persistence;

import edu.Ufes.exeSwing.Model.Gerente;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.TreeSet;

/**
 *
 * @author bhetynnacatalunha
 */
public class GerentePersistence {
    public boolean salvarGerente(TreeSet<Gerente> pGerentes){

        boolean retorno = false;

        try {
            FileOutputStream arquivoGerente = new FileOutputStream("data/Gerente.pas");
            ObjectOutputStream ooGerentes = new ObjectOutputStream(arquivoGerente);
            ooGerentes.writeObject(pGerentes);
            ooGerentes.close();
            retorno = true;

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        return retorno;

    }
    
    public TreeSet<Gerente> recuperarGerente(){
    
        TreeSet<Gerente> gerentes = new TreeSet<Gerente>();
        
        try{
            File arquivoGerente = new File("data/Gerente.pas");
            FileInputStream fiGerente = new FileInputStream(arquivoGerente.getAbsolutePath());
            ObjectInputStream oiGerente = new ObjectInputStream(fiGerente);
            gerentes = (TreeSet<Gerente>) oiGerente.readObject();
            oiGerente.close();
        }catch(Exception e){
            System.err.println(e.getMessage());
        }
        return gerentes;
    }
}
